package com.example.lets;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.gc.materialdesign.widgets.SnackBar;

import cn.bmob.v3.BmobUser;
import cn.bmob.v3.listener.SaveListener;

public class FeedbackActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_feedback);

        Toolbar toolbar = (Toolbar) this.findViewById(R.id.feedback_toolbar);
        toolbar.setTitle("给我们反馈");
        setSupportActionBar(toolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });

        ///
        /// send
        ///
        toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem item) {
                TextView text = (TextView) findViewById(R.id.feedback_text);
                String content = text.getText().toString();
                if (content.equals("")) {
                    new SnackBar(FeedbackActivity.this, "请填写些反馈内容吧！", null, null).show();
                    return true;
                }
                Feedback fb = new Feedback();
                fb.setUser(BmobUser.getCurrentUser(FeedbackActivity.this, User.class));
                fb.setContent(content);
                fb.save(FeedbackActivity.this);
                new SnackBar(FeedbackActivity.this, "发送成功！感谢您的反馈！:)", null, null).show();
                return true;
            }
        });
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.feedback, menu);
        return true;
    }

    @Override
    public void onBackPressed() {
        finish();
        return;
    }
}
